package com.ashok.mvc.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {
	private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
	@RequestMapping(value="/login")
	public String getLoginPage(ModelMap model,
			@RequestParam(value = "error", required = false) boolean error) {
		LOGGER.info("You are trying to access >>> /login.html");
		if(error==true){
			LOGGER.error("You have entered invalid username or password");
			model.addAttribute("error","you have entered wrong username or password");
		}else{
			model.addAttribute("error", "");
		}
		return "loginpage";
	}
	
	@RequestMapping(value="/denied")
	public String getDeniedPage(){
		LOGGER.info("You have entered invalid username or password");
		return "deniedpage";
	}
}
